package itbour.onetouchshow.activity.version1_6;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andview.adapter.BaseRecyclerHolder;
import com.ys.uilibrary.swip.SwipeMenuLayout;

import java.util.ArrayList;
import java.util.List;

import itbour.onetouchshow.R;
import itbour.onetouchshow.base.BaseRefreshAdapter;
import itbour.onetouchshow.bean.canvas.CompoundPathsBean;
import itbour.onetouchshow.bean.canvas.PosBean;
import itbour.onetouchshow.bean.inching.noppt.InchingCoreRootNoPPTV10Bean;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;
import itbour.onetouchshow.utils.UIUtils;
import itbour.onetouchshow.widget.ClearEditTextView;

/**
 * Created by zjl_d on 2017/12/5.
 */

public class VideoEditAdapterVTest extends BaseRefreshAdapter<InchingCoreRootNoPPTV10Bean> {
    MakeActivityV1_6 context;
    TextView mTvChange;
    LinearLayout mBtnDelete;
    ImageView mRenameIg;
    ImageView mVideoPaly;
    ClearEditTextView mEditTextViews;
    TextView mTvCount;
    OnScrollToListener onScrollToListener;
    private List<SwipeMenuLayout> mSwipeMenuLayout = new ArrayList<>();
    private List<InchingCoreRootNoPPTV10Bean> mListData;
    private int mpostion;
    //点击图片的接口，可返回该图片携带的数据，可从editValueBean中获取截图的路径，根据路径绘制截图形状
    private OnPictureIvClickListener onPictureIvClickListener;

    public VideoEditAdapterVTest(Context context, List<InchingCoreRootNoPPTV10Bean> datas, int itemLayoutId) {
        super(context, datas, itemLayoutId);
        mListData = datas;
    }


    @Override
    protected void convert(BaseRecyclerHolder var1, InchingCoreRootNoPPTV10Bean var2, int position) {
        Integer type = var2.getType();
        if (type == AppConst.ROOT_VALUE_TEXT) {
            // View textView = getTextView();
            ClearEditTextView editTextView = var1.getView(R.id.et_text_valuel);
            editTextView.setText("position:" + position + "var2:" + var2.getTopic());
            editTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    L_.i("getTextView===" + hasFocus);
                    if (hasFocus) {
                        setMpostion(position);
                        setmEditTextViews(editTextView);
                    }
                }
            });
        } else if (type == AppConst.ROOT_VALUE_IMG) {
        } else if (type == AppConst.ROOT_VALUE_VIDEO) {
        }
    }


    @Override
    public BaseRecyclerHolder onCreateViewHolder(ViewGroup viewGroup, int type, boolean b) {
        View view = null;
        if (type == AppConst.ROOT_VALUE_TEXT) {
            view = getTextView();
        } else if (type == AppConst.ROOT_VALUE_IMG) {
            view = getImageView();
        } else if (type == AppConst.ROOT_VALUE_VIDEO) {
            view = getVideoView();
        }
        return new BaseRecyclerHolder(view);
    }

    @Override
    public int getItemViewType(int position) {
        InchingCoreRootNoPPTV10Bean inchingCoreRootNoPPTV10Bean = mListData.get(position);
        Integer type = inchingCoreRootNoPPTV10Bean.getType();
        return type;
    }


    private View getImageView() {
        // final View inflate = View.inflate(context, R.layout.video_adapter_img_type, null);
        View imageView = UIUtils.inflate(R.layout.video_adapter_img_type);
//        SwipeMenuLayout swipeMenuLayout = imageView.findViewById(R.id.id_root_swp);
//        mSwipeMenuLayout.add(swipeMenuLayout);
//        // setVideoBound(data);
//        LinearLayout btnDelete = imageView.findViewById(R.id.btnDelete_ly);
//        LinearLayout btnReName = imageView.findViewById(R.id.btnReName_ly);
//        ImageView edit_img_hint = imageView.findViewById(R.id.edit_img_hint);
//        RelativeLayout boundRoot = imageView.findViewById(R.id.id_bound_rot);
//        TextView tvTip = imageView.findViewById(R.id.tv_img_tip);
//        TextView tvImageChange = (TextView) imageView.findViewById(R.id.id_tv_chage);
//        ImageView renameIg = (ImageView) imageView.findViewById(R.id.id_icon_rename);
//        TextView title = (TextView) imageView.findViewById(R.id.tv_video_img_title);
        return imageView;
    }


    public void startShowPhotoActivity(String imageUrl, CompoundPathsBean bound, PosBean posBean) {
        //确定当前选中的位置
        int centerWidth = UIUtils.WHD()[0];
        int pageWidth = context.noPptCoreData.getPageWidth();
        int pageHeight = context.noPptCoreData.getPageHeight();
        float scaleWH = pageWidth * 1.0f / pageHeight;
        // float scaleW = centerWidth * 1.0f / pageWidth;
        int centerHeight = (int) (centerWidth / scaleWH);
        Intent intent = ShowPhotoActivity.getLaunchIntent(context, imageUrl, centerWidth, centerHeight, pageWidth, pageHeight, bound, posBean);
        context.startActivity(intent);
    }


    private View getVideoView() {

        //final View inflate = View.inflate(context, R.layout.video_adapter_img_type, null);
        View videoView = UIUtils.inflate(R.layout.video_adapter_img_type);

        return videoView;
    }


    public int getMpostion() {
        return mpostion;
    }

    public void setMpostion(int postion) {
        this.mpostion = postion;
        T_.showToastReal("当前选择的行数" + mpostion);
        L_.e("当前选择的行数" + mpostion);
    }

    public ClearEditTextView getmEditTextViews() {
        return mEditTextViews;
    }

    public void setmEditTextViews(ClearEditTextView mEditTextViews) {
        this.mEditTextViews = mEditTextViews;
    }

    private View getTextView() {
        View textView = UIUtils.inflate(R.layout.test_adapter_text_type);
        // final View inflate = View.inflate(context, R.layout.video_adapter_text_type, null);
//        TextView title = (TextView) textView.findViewById(R.id.tv_video_text_title);
//        ClearEditTextView editTextView = (ClearEditTextView) textView.findViewById(R.id.et_text_valuel);
//        // mEditTextViews.add(editTextView);
//        TextView tvCount = (TextView) textView.findViewById(R.id.tv_text_count);
//        ImageView imageClean = (ImageView) textView.findViewById(R.id.id_clean_all);
//
//        ImageView edit_img_hint = textView.findViewById(R.id.edit_img_hint);
//        RelativeLayout boundRoot = textView.findViewById(R.id.id_bound_rot);

        return textView;
    }


    public void setOnPictureIvClickListener(OnPictureIvClickListener onPictureIvClickListener) {
        this.onPictureIvClickListener = onPictureIvClickListener;
    }

    public void setOnScrollToListener(OnScrollToListener onScrollToListener) {
        this.onScrollToListener = onScrollToListener;
    }


    public interface OnPictureIvClickListener {
        void getPictureIv();


        void addBoundView(InchingCoreRootNoPPTV10Bean data);

        void removeBoundView();


        void getCurrentPic(int position, String url);
    }

    public interface OnScrollToListener {
        void scrollTo(EditText editText, int postion);
    }

}
